<?php namespace Home\Controller;
use Common\Model\Login;
use Common\Model\User;

class UserController extends CommonController{

    public function index(){
        if(IS_AJAX){
            $loginModel=new Login();
            if(!$loginModel->Login()){
                $this->ajax(['status'=>false,'message'=>$loginModel->getError()]);
            }else{
                $this->ajax(['status'=>true,'message'=>'登陆成功']);
            }

        }
        View::make();
    }

    public function reg(){
        if(IS_AJAX){
            $userModel=new User();
            if(!$userModel->store()){
                $this->ajax(['status'=>false,'message'=>$userModel->getError()]);
            }else{
                $this->ajax(['status'=>true,'message'=>'注册成功']);
            }

        }
        View::make();
    }


//    设置验证码的长度
    public function code(){
        Code::num(1)->make();
    }

    public function out(){
        unset($_SESSION['userinfo']);
        unset($_SESSION['cart']);
        go(U('Index/index'));
    }
}